package com.itheima.web;

import com.itheima.pojo.Employee;
import com.itheima.result.R;
import com.itheima.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @Author: 斌
 * @DateTime: 2023年02月05日  20:33:49
 * @Description: com.itheima.web
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 登录
     * @param employee
     * @param session
     * @return
     */
    @PostMapping("/login")
    public R login(@RequestBody Employee employee, HttpSession session){
        log.info("开始登录........");
       return employeeService.login(employee,session);
    }

    /**
     * 退出
     * @param session
     * @return
     */
    @PostMapping("/logout")
    public R login(HttpSession session){
        return employeeService.logout(session);
    }

    /**
     * 分页查询
     * @param employee
     * @return
     */
    @GetMapping("/page")
    public R tabs(Integer page,Integer pageSize,Employee employee){
        return employeeService.tabs(page,pageSize,employee);
    }
    @PostMapping()
    public R addEmp(@RequestBody Employee employee,HttpSession session){
       return employeeService.addEmp(employee,session);
    }
    @PutMapping()
    public R updateStatus(@RequestBody Employee employee,HttpSession session){
        return employeeService.updateStatus(employee,session);
    }
    @GetMapping("/{id}")
    public R queryEmpById(@PathVariable Long id){
        return employeeService.queryEmpById(id);
    }

}
